//
//  MyDynamicViewController.m
//  YiXiu
//
//  Created by ZHY on 16/6/29.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "MyDynamicViewController.h"
#import "SegementedControl.h"
#import "AutoSizeTableViewCell.h"

@interface MyDynamicViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UISegmentedControl *segment;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *arr;

@property (nonatomic, strong) NSArray * cellModels;





@end

@implementation MyDynamicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的消息";
    
    self.view.backgroundColor = [UIColor blackColor];
    
    
    
    NSMutableArray * Marr = [NSMutableArray array];
    for (int i = 0; i < 30; i++) {
        AutoSizeModel * model = [[AutoSizeModel alloc] init];
        model.contentText = @"一羞（武汉）科技有限公司，致力于两性健康，深度研讨两性话题，带给你不一样的感受，摈弃约束，不做白纸，为了新生活-----大沙发上感受感受公司附近快速公交好多个风格上岛咖啡看黄FKHLSHFS。";
        model.name = @"一羞大师";
        model.isHot = i > 6;
        model.contentText = [model.contentText substringFromIndex:i];
        model.contentTextFont = [UIFont systemFontOfSize:18];
        //        model.contentText = nil;
        
        //        model.contentImages = @[@"asdfasfd"];
        model.contentImages = nil;
        
        //
        model.Zang = [NSString stringWithFormat:@"%d",i+300];
        model.Pinlun = [NSString stringWithFormat:@"%d",i+3000];
        model.Fenxian = [NSString stringWithFormat:@"%d",i+200];
        //        [model.Zang setImage:[UIImage imageNamed:@"icon_n1"] forState:UIControlStateNormal];
        
        [Marr addObject:model];
    }
    
    self.cellModels = Marr;

    
    self.navigationItem.titleView =  [self setUpSegement];
    [self.view addSubview:self.tableView];
    
    
   
    
    
    
}

- (SegementedControl *)setUpSegement{
    
    SegementedControl *control = [[SegementedControl alloc] initWithItems:@[@"图文",@"声音"]];
    control.frame = CGRectMake(0, 0, 200, 25);
    
    control.layer.cornerRadius = 10;
    
    control.layer.borderWidth = 1.1;
    control.layer.borderColor = [UIColor blackColor].CGColor;
    
    control.selectedSegmentIndex = 0;//设置默认选择项索引
    [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventValueChanged];
    
    return control;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}


- (void)controlAction:(UISegmentedControl *)control{
    switch (control.selectedSegmentIndex) {
        case 0:{
            
//            self.arr = @[@"张航宇",@"张航宇1",@"张航宇2",@"张航宇3",@"张航宇4",@"张航5",@"张航宇6",@"张航宇7"];
            NSMutableArray * Marr = [NSMutableArray array];
            for (int i = 0; i < 30; i++) {
                AutoSizeModel * model = [[AutoSizeModel alloc] init];
                model.contentText = @"一羞（武汉）科技有限公司，致力于两性健康，深度研讨两性话题，带给你不一样的感受，摈弃约束，不做白纸，为了新生活-----大沙发上感受感受公司附近快速公交好多个风格上岛咖啡看黄FKHLSHFS。";
                model.name = @"一羞大师";
                model.isHot = i > 6;
                model.contentText = [model.contentText substringFromIndex:i];
                model.contentTextFont = [UIFont systemFontOfSize:18];
                //        model.contentText = nil;
                
                //        model.contentImages = @[@"asdfasfd"];
                model.contentImages = nil;
                
                //
                model.Zang = [NSString stringWithFormat:@"%d",i+300];
                model.Pinlun = [NSString stringWithFormat:@"%d",i+3000];
                model.Fenxian = [NSString stringWithFormat:@"%d",i+200];
                //        [model.Zang setImage:[UIImage imageNamed:@"icon_n1"] forState:UIControlStateNormal];
                
                [Marr addObject:model];
            }
            
            self.cellModels = Marr;
            [self.tableView reloadData];
        }
            
            break;
            
        case 1:{
            self.arr = @[@"张航宇00",@"张航宇11",@"张航宇22",@"张航宇33",@"张航宇44",@"张航55",@"张航宇66",@"张航宇77"];          [self.tableView reloadData];
            
        }
            
            break;
            
            
        default:
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"mycell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.textLabel.text = self.arr[indexPath.row];
    return cell;
}




- (UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    
    return _tableView;
}






@end
